#!/bin/sh

if test -z "$1" || test -z "$2"
then
   echo "Usage: $0 [IP] [Script]"
   exit 0
fi

# Copyright(c) 2011 OpenDomo Services SL. Licensed under GPL v3 or later

#TODO Accept fingerprint always
#TODO If the agent $IP is down, return error code and exit (*)

IP="$1"
#TODO Store a distinct password file for each host?
PASSWORD=`cat /etc/opendomo/discovery/password`
SSHBATCH="/usr/bin/sshbatch passw $PASSWORD host "

#FIXME Execute the command with the same user that is executing this
$SSHBATCH admin@$IP exec "$2"

# (*) si el agente que debe ejecutar el comando no se encuentra activo, podrá
#     intentarlo el siguiente agente que disponga del servicio.
